import unittest
import requests
from ddt import ddt,file_data

# @ddt
class health(unittest.TestCase):
    host = 'http://10.59.9.18'
    def setUp(self) -> None:
        print('start case')
    def tearDown(self) -> None:
        print('case end')
    # 医生登录
    keshiID = None
    doctorId = None
    sessionId = None
    # @file_data('aa.json')
    # , email, pwd
    def test_01(self):
        url = health.host+'/health/doctor/v1/login'
        # par = {"email":email, "pwd":pwd}
        par = {"email":"2306398720@qq.com", "pwd":"lZjdXyj15cOhn1a0yJKsW7o+fw/ogBDzn6CcyPSJUVIMmCPtCs+zuPwh7IZkXZiRhJvvjdIz9D2z1jkMOtD/36ddaLFMtQd9xIk0jAaDP1TH/lEHvvUPwot6asMGMGkH9EgBPT+4eaYC77BGQBPOASweQZE5KDF8BeN/c0sLfSw="}
        r = requests.post(url=url, params=par).json()
        print(r)
        health.keshiID = r['result']['departmentId']
        health.doctorId = str(r['result']['doctorId'])
        health.sessionId = r['result']['sessionId']
        print('科室id',health.keshiID)
        print('医生id',health.doctorId)
        print('医生sessionid',health.sessionId)
        self.assertIn('109',str(health.sessionId))
        print('通过')

    # 用户登录
    userid = None
    usersessionid = None
    def test_02(self):
        url = health.host+'/health/user/v1/login'
        par = {"email":"3500186206@qq.com", "pwd":"lZjdXyj15cOhn1a0yJKsW7o+fw/ogBDzn6CcyPSJUVIMmCPtCs+zuPwh7IZkXZiRhJvvjdIz9D2z1jkMOtD/36ddaLFMtQd9xIk0jAaDP1TH/lEHvvUPwot6asMGMGkH9EgBPT+4eaYC77BGQBPOASweQZE5KDF8BeN/c0sLfSw="}
        r = requests.post(url=url,params = par).json()
        print(r)
        health.userid = r['result']['userId']
        health.usersessionid = r['result']['sessionId']
        print('用户id', health.userid)
        print('用户sessionid', health.usersessionid)
        self.assertEqual('598', str(health.userid))
        print('通过')

    # 签到
    def test_03(self):
        url = health.host + '/health/user/verify/v1/addSign'
        header = {"userId": str(health.userid), "sessionId": health.usersessionid}
        r = requests.post(url=url, headers=header).json()
        print(r)
        self.assertTrue('今天已签到'==r['message'])
        print('通过')



    # 患者发送消息
    def test_04(self):
        url = health.host+'/health/user/inquiry/verify/v1/pushMessage'
        header = {"userId": str(health.userid), "sessionId": health.usersessionid}
        pa = {'inquiryId':23,'content':"我是患者1",'type':1,'doctorId':health.doctorId}
        r = requests.post(url=url, headers=header,params=pa).json()
        print(r)

    # 医生发消息
    def test_05(self):
        url = health.host+'/health/doctor/inquiry/verify/v1/pushMessage'
        hea = {"doctorId": health.doctorId, "sessionId": health.sessionId}
        pa = {'inquiryId': 23, 'content': "我是患者1", 'type': 1, 'userId': health.userid}
        r = requests.post(url=url,headers=hea,params=pa).json()
        print(r)



    recordId = None
    # 查询医生历史问诊记录列表
    def test_06(self):
        url = health.host + '/health/doctor/inquiry/verify/v1/findHistoryInquiryRecord'
        hea = {"doctorId": health.doctorId, "sessionId": health.sessionId}
        pa = {"page": 1, "count": 5}
        r = requests.get(url=url, headers=hea, params=pa).json()
        print(r)
        health.recordId = r['result'][0]['recordId']
        print('聊天记录id', health.recordId)

    # 医生结束问诊
    def test_07(self):
        url = health.host + '/health/doctor/inquiry/verify/v1/endInquiry'
        header = {"doctorId": health.doctorId, "sessionId": health.sessionId}
        par = {"recordId": health.recordId}
        r = requests.put(url=url, headers=header, data=par).json()
        print(r)
        # 查询历史问诊聊天记录
    def test_08(self):
        url = health.host + '/health/user/inquiry/verify/v1/findInquiryRecordList'
        header = {"userId": str(health.userid), "sessionId": health.usersessionid}
        pa = {"inquiryId": 23, "page": 1, "count": 5}
        r = requests.get(url=url, headers=header, params=pa).json()
        print(r)



if __name__ == '__main__':
    unittest.main()